/**
* HTML接收参数
*/
function  getRequestByName(paramName)
{
	//获取URL的字符串
	var sSource=String(window.document.location);
	var sName= paramName;  
	var sReturn="";   
	var sQUS="?";   
	var sAMP="&";   
	var sEQ="=";   
	var iPos;

	//获取sSource中的"?"，无则返回 -1
	iPos=sSource.indexOf(sQUS);
	if(iPos==-1) 
		return; 
	
	//汲取参数，从iPos位置到sSource.length-iPos的位置，
	//若iPos = -1，则：从-1 到 sSource.length+1
	var strQuery=sSource.substr(iPos,sSource.length-iPos); 

	// alert(strQuery); 
	//先全部转换为小写
	var   strLCQuery = strQuery.toLowerCase();   
	var   strLCName  = sName.toLowerCase(); 

	//从子字符串strLCQuery中查找“?”、参数名，以及“=”，即“?参数名=”
	iPos   = strLCQuery.indexOf(sQUS + strLCName + sEQ);
	//alert(iPos);
	//如果不存在
	if(iPos == -1)   
	{   
		//继续查找可能的后一个参数，即带“&参数名=”
		iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);   
	}

	//判断是否存在参数
	if(iPos != -1)
	{    
		sReturn = strQuery.substr(iPos + sName.length + 2,strQuery.length-(iPos + sName.length + 2));   
		var iPosAMP = sReturn.indexOf(sAMP);   
		if (iPosAMP == -1)
		{
			return   sReturn;   
		}
		else
		{   
			sReturn = sReturn.substr(0,iPosAMP);   
		}   
	}
	return   sReturn; 
}



//截取字符串区分中英文
function mySubString(str,startLen, len) {
  var newLength = 0;
  var newStr = "";
  var chineseRegex = /[^\x00-\xff]/g;
  var singleChar = "";
  var strLength = str.replace(chineseRegex,"**").length;
  for(var i = 0;i < strLength;i++) {
          singleChar = str.charAt(i).toString();
          if(singleChar.match(chineseRegex) != null) {
                  newLength += 2;
          }else {
                  newLength++;
          }
		            if (newLength > len) {
			break;
		}
		newStr += singleChar;
	}
	if (strLength > len) {
		newStr += "..."; 
	}
	return newStr;
};


//格式化标题，显示20个字
function comChangeTitle(title) {
	var nowWord;
	var nowLeng = contentLength(title);
	if (nowLeng > 19) {
		nowWord = mySubString(title, 0, 20);
	} else {
		nowWord = title;
	}
	return nowWord;
};


//格式化标题，自定义
function changeTitleDiy(title,len){
	var nowWord;
	var nowLeng = contentLength(title);
	if (nowLeng > len-1) {
		nowWord = mySubString(title, 0, len);
	} else {
		nowWord = title;
	}
	return nowWord;
};

//返回文字内容长度
function contentLength(content) {
	var intLength = 0
	for ( var i = 0; i < content.length; i++) {
		if ((content.charCodeAt(i) < 0) || (content.charCodeAt(i) > 255))
			intLength = intLength + 2
		else
			intLength = intLength + 1
	}
	return intLength
};
//对象不为空
function isNotEmpty(obj){
    var isflag = false;
    if(obj!=null&&obj!=''&&obj!=undefined&&obj!='undefined'){
        isflag = true;
    }
    return isflag;
};


/**
 *封装Ajax</br>
 *参数说明：</br>
 * opts: {'可选参数'}</br>
 * type: 请求方式:GET/POST,默认值:'GET';</br>
 * url:    发送请求的地址, 默认值: 当前页地址;</br>
 * data: 请求参数;</br>
 * data: string,json;</br>
 * async: 是否异步:true/false,默认值:true;</br>
 * cache: 是否缓存：true/false,默认值:true;</br>
 * contentType: HTTP头信息，默认值：'application/x-www-form-urlencoded';</br>
 * success: 请求成功后的回调函数;</br>
 * error: 请求失败后的回调函数;</br>
 */
function ajaxRequest(opts) {
	//一.设置默认参数
	var defaults = {
		url : '',
		type : '',
		data : '',
		cache : true,
		async : false,
		dataType : 'json',
		contentType : "application/json;charset=UTF-8",
		success : function() {},
		error : function() {}
	};

	//二.用户参数覆盖默认参数    
	for ( var key in opts) {
		defaults[key] = opts[key];
	}

	//三.开始组装ajax
	$.ajax({
		url : defaults.url,
		type : defaults.type,
		data : defaults.data,
		async : defaults.async,
		cache : defaults.cache,
		dataType : defaults.dataType,
		contentType : defaults.contentType,
		beforeSend :function(XHR){
			//TODO 设置登录信息
			XHR.setRequestHeader("tenantId","1234");
			XHR.setRequestHeader("loginUserId","0003");
		},
		error : defaults.error,
		success : defaults.success
	});
}

/**
 * 获取当前登录用户所属栏目的所用用户
 */
function getAllUsers() {
	var users = null;
	ajaxRequest({
			type : 'GET',
			contentType : "application/json;charset=utf-8",
			url : systemConfig.serverPath+"user/getAllUser",
			success : function(data) {
				if(data.status == true){
					users = data.data;
				}else{
					Global.alert(data.msg);
				}
			}
	});
	return users;
}
/**
 * 获取当前登录用户所有
 */
function getColumns() {
	var columns = null;
	ajaxRequest({
			type : 'GET',
			contentType : "application/json;charset=utf-8",
			url : systemConfig.serverPath+"user/getUserColumns",
			success : function(data) {
				if(data.status == true){
					columns =  data.data;
				}else{
					Global.alert(data.msg);
				}
			}
	});
	return columns;
}
/**
 * 判断地址正则
 */
function  isPath(strValue )  {  
   var  objRegExp= /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{0,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g;
   return  objRegExp.test(strValue);  
}  